package com.xyh;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;

import java.util.Arrays;
import java.util.Properties;

public class ConsumerMain {
    public static void main(String[] args){
        Properties properties=new Properties();
        properties.put("bootstrap.servers","localhost:9092");
        properties.put("group.id","test");
        properties.put("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
        properties.put("value.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer<String,String> consumer=new KafkaConsumer<String, String>(properties);
        consumer.subscribe(Arrays.asList("my-topic"));
        while (true){
            ConsumerRecords<String, String> records=consumer.poll(100);
            for ( ConsumerRecord<String,String> record:records ){
                System.out.println("key:"+record.key()+",value:"+record.value());
            }

        }

    }
}
